<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>鲜知校园-勾选-推送时间</title>
    <link rel="stylesheet" href="/static/front/common/css/reset.css" />
    <link rel="stylesheet" href="/static/front/css/pushTime.css" />
    <link rel="stylesheet" href="/static/front/css/common.css" />
    <link rel="stylesheet" href="/static/layer_mobile/need/layer.css" />
    <script src="/static/front/common/js/jquery-1.12.4.min.js"></script>
    <script src="/static/layer_mobile/layer.js"></script>
</head>

<body>
    <div class="container">
        <p class="title">
            选择推送时间:
        </p>
        <!-- 内容列表 -->
        <div class="content">
            <ul>
                {{range .pushTimeList}}
                    <li>
                        <div class="contain">
                            <p>{{.Month}}</p>
                            <p>{{.Publication}}</p>
                            <p>{{.Num}}次</p>
                        </div>
                        <div class="selected noSelected" data-push_time_id="{{.Id}}">
                            <img src="/static/front/img/noSelected.png" alt="">
                        </div>
                    </li>
                {{end}}
            </ul>
        </div>
        <div class="submit">
            <img src="/static/front/img/submit_white.png" alt="">
        </div>
    </div>
    <form id="data-form">
        {{.xsrfdata}}
        <input type="hidden" name="id" value="{{.setMealId}}">
        <input type="hidden" id="push_time_ids" name="push_time_ids" value="">
    </form>
    {{template "common/bottom-nav.html" .}}
</body>

<script type="text/javascript">

    var canSubmit = true;

    $(function () {

        $('.content').on('click', '.selected', function () {
            if ($(this).hasClass('noSelected')) {
                $(this).removeClass("noSelected").addClass("isSelected");
                $(this).find("img").attr("src", '/static/front/img/selected.png');
            }else {
                $(this).addClass("noSelected").removeClass("isSelected");
                $(this).find("img").attr("src",'/static/front/img/noSelected.png')
            }
        });

        $('.submit').click(function () {
            var ids = [];
            $('.isSelected').each(function () {
                ids.push($(this).data('push_time_id'));
            });
            if (ids.length <= 0) {
                layer.open({content: '您没有选择任何推送时间', skin: 'msg', time: 2});
                return false;
            }
            $('#push_time_ids').val(ids.join(','));
            doSubmit();
        });

    });

    function doSubmit() {

        if (!canSubmit) return false;
        var loadIndex = layer.open({type: 2});
        canSubmit = false;

        $.ajax({
            url: '{{urlfor "controllers.OrderController.Add"}}',
            type: 'POST',
            data: $('#data-form').serialize(),
            dataType: 'json',
            success: function (res) {

                canSubmit = true;
                layer.close(loadIndex);

                layer.open({content: res.msg, skin: 'msg', time: 2});
                if (res.status == 1) {
                    setTimeout(function () {
                        location.href = '{{urlfor "controllers.OrderSchoolController.PublicSpace"}}';
                    }, 1000);
                }

            }
        });

    }

</script>

</html>